<template>
  <div
    class="sc-header"
    :style="{ background: colors.header.bg, color: colors.header.text }"
  >
    <div v-if="showCloseButton" class="sc-header--close-button">
      <el-tooltip effect="dark" content="缩小对话框" placement="bottom">
        <i @click="$emit('close')" class="el-icon-minus pointer"></i>
      </el-tooltip>
    </div>
    <slot>
      <img
        v-if="titleImageUrl"
        class="sc-header--img"
        :src="titleImageUrl"
        alt=""
      />
      <div
        v-if="!disableUserListToggle"
        class="sc-header--title enabled"
        @click="toggleUserList"
      >
        {{ title }}
      </div>
      <div v-else class="sc-header--title">{{ title }}</div>
    </slot>
  </div>
</template>

<script>
import { mapState } from "@/store/modules/chat";

export default {
  name: "ChatHeader",
  props: {
    title: {
      type: String,
      required: true,
    },
    colors: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      inUserList: false,
    };
  },
  computed: {
    ...mapState(["disableUserListToggle", "titleImageUrl", "showCloseButton"]),
  },
  methods: {
    toggleUserList() {
      this.inUserList = !this.inUserList;
      this.$emit("userList", this.inUserList);
    },
  },
};
</script>

<style scoped>
.sc-header {
  /* min-height: 75px; */
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
  border-bottom: 1px solid #e5e6eb;
  padding: 6px 20px;
  position: relative;
  box-sizing: border-box;
  display: flex;
}

.sc-header--img {
  border-radius: 50%;
  align-self: center;
  padding: 10px;
}

.sc-header--title {
  align-self: center;
  padding: 10px;
  flex: 1;
  user-select: none;
  font-size: 20px;
}

.sc-header--title.enabled {
  cursor: pointer;
  border-radius: 5px;
}

.sc-header--title.enabled:hover {
  box-shadow: 0px 2px 5px rgba(0.2, 0.2, 0.5, 0.1);
}

.sc-header--close-button {
  width: 88px;
  font-size: 20px;
  line-height: 32px;
}

.sc-header--close-button img {
  width: 100%;
  height: 100%;
  padding: 13px;
  box-sizing: border-box;
}

.pointer {
  cursor: pointer;
}

@media (max-width: 450px) {
  .sc-header {
    border-radius: 0px;
  }
}
</style>
